import urllib

import execjs
import requests


headers = {
    "accept": "application/json, text/plain, */*",
    "accept-language": "zh-CN,zh;q=0.9",
    "cache-control": "no-cache",
    "content-length": "0",
    "content-type": "application/x-www-form-urlencoded; charset=UTF-8",
    "origin": "https://live.douyin.com",
    "pragma": "no-cache",
    "priority": "u=1, i",
    "referer": "https://live.douyin.com/699918634417?column_type=single&from_search=true&is_aweme_tied=1&search_id=202505071623509831F545AE76D1004C6E&search_result_id=7501563885321833765",
    "sec-ch-ua": "\"Not_A Brand\";v=\"99\", \"Chromium\";v=\"142\"",
    "sec-ch-ua-mobile": "?0",
    "sec-ch-ua-platform": "\"Windows\"",
    "sec-fetch-dest": "empty",
    "sec-fetch-mode": "cors",
    "sec-fetch-site": "same-origin",
    "uifid": "undefined",
    "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36",
    "x-secsdk-csrf-token": "000100000001780365b1cab93b3d5f157c71a84f51b47b4e421802f15166787f4db7d0bcda3918656fb9c7936716"
}
cookies = {
    "__ac_nonce": "068c7f19f00ec6f7e333",
    "__ac_signature": "_02B4Z6wo00f015Shf5gAAIDCmV1AfYo4TsuUgXsAAI34f2",
    "x-web-secsdk-uid": "16a4d509-71c2-4168-a0be-20118504493b",
    "xgplayer_device_id": "55746091393",
    "xgplayer_user_id": "980885048486",
    "__live_version__": "%221.1.3.9904%22",
    "has_avx2": "null",
    "device_web_cpu_core": "16",
    "device_web_memory_size": "8",
    "live_use_vvc": "%22false%22",
    "csrf_session_id": "fb00e7c43059470692631b9a8d289091",
    "hevc_supported": "true",
    "h265ErrorNum": "1",
    "webcast_local_quality": "sd",
    "fpk1": "U2FsdGVkX19c2KznP03OPdh5Ih2BQ5PYWk5rUjdSAFv3r+DKr1hjwKcC8vz2Uwtyu4hGk/4wpVeSXGlptblnzA==",
    "fpk2": "3c9fc7ddec9b58823c1c96756dbd45d8",
    "passport_csrf_token": "4dbee7d17ce81e1a8ba179f2dfc94265",
    "passport_csrf_token_default": "4dbee7d17ce81e1a8ba179f2dfc94265",
    "sdk_source_info": "7e276470716a68645a606960273f276364697660272927676c715a6d6069756077273f276364697660272927666d776a68605a607d71606b766c6a6b5a7666776c7571273f275e58272927666a6b766a69605a696c6061273f27636469766027292762696a6764695a7364776c6467696076273f275e5827292771273f27313c3437353531363c323032342778",
    "bit_env": "APe--kpuOZy-L7ZqKEfgwfU5m1RxeixHsyx8_oOLQpD5LtEVl2HUM_AdgqJO5zf2JhOtRiqgHLKc_mP4opwie4-_-limVDDz71tPYOdzrqZkawW5aINXrOKuOZbZfM4-Tu2kSeRogXLq0cc8t3DsUkt0AMUtynTF6rdm1DP3SL_INVrltoXL0erP0qmNdXXqXa4i4Y4td48Ifo9-dYJQK92ckCx0iiwd9V0wOpADaTnvZsZxdjADFIXemd7MdIAYjCy2QDTvW5bNpvjhEbqxE6ti_PlAisM-WEUamjOHqZN5SPCtOVr3mzpfHeNhHpqtPVV3urnA5EFlJGiyMDqwTmlCGbKw88WAKYU-x_XnmGXwXylJN8m-JUnGAH8GjXyqOAFmNB0raiBWkB4IybqoIqh21iTqDELqFPrnuSslb5pP32J2-aIFwyfOtS7j3SduJhBEWeqAiCQscpaVbUeSAgI9D-f4P8sgncJEaQoSK0WqSN2P--kqCdi7yk_9y9JD",
    "gulu_source_res": "eyJwX2luIjoiZDg5ZGRhM2JhYWRjMGY2Yzk3MDk4ZWM2Nzk1MTFlZjJjMGMwZTFmMDUyZTBlMTI5MzRkNDg2YzhlM2JjYmZkOSJ9",
    "passport_auth_mix_state": "92pij0bsqmho2nj0ygutqir4ymemcbjod8w8nl5t1r7p9il1",
    "__security_mc_1_s_sdk_crypt_sdk": "b5b42448-404a-ac2e",
    "bd_ticket_guard_client_data": "eyJiZC10aWNrZXQtZ3VhcmQtdmVyc2lvbiI6MiwiYmQtdGlja2V0LWd1YXJkLWl0ZXJhdGlvbi12ZXJzaW9uIjoxLCJiZC10aWNrZXQtZ3VhcmQtcmVlLXB1YmxpYy1rZXkiOiJCSmRldmd5UDhCSSs4SWFSRXI3MS8yeDRPNlVGekhueUVNMnVkamc3T0ROcVg3dU5uTUpXUHE3aEM4WWNvd1ZnN29Ua0FqL0xYeWtYOVBES1B6OFd2UGM9IiwiYmQtdGlja2V0LWd1YXJkLXdlYi12ZXJzaW9uIjoyfQ%3D%3D",
    "bd_ticket_guard_client_web_domain": "2",
    "ttwid": "1%7CQXTKrok9KG68_r4hAqXUaZ3VO7yJEnlJZlsUdeNV818%7C1757934057%7Cabff6b2550ba50d2f7e0019c0d5e5ec15cee10a6927c5b77c70bcacf4ea5f778",
    "download_guide": "%221%2F20250915%2F0%22",
    "passport_mfa_token": "CjeUC8QPVG1DZXWzssX6fZnHHpo5EcdleHwT8aWBLscYx3xe%2FiQZLb%2FUroR6qmkjPI8qcCM6zxF3GkoKPAAAAAAAAAAAAABPerYL15rETB6OgMBtjidDNHMMmHNYrr2G%2F5XXdPe71UFA9zwhnvo%2BLaMchZuWrTW7HRDzn%2FwNGPax0WwgAiIBA7IxErM%3D",
    "d_ticket": "b5c3c187410a9b681f64617b57b2b653b8765",
    "odin_tt": "0e43ab3035fd981fe08897f54481e93e991a4c2ff1f7ea3fcda0be2cf524a820faeeee140d24c06952c5e6494d381ad8312166c2a13249b3e669bd2b410f98e9",
    "passport_assist_user": "CkHP4BsejxSMU5JtntvxlcnXWdsXrWq2mhv0mAzTSG1Rpqah943vDVWNrK8y8iPvsI3zz8KBNXybIINrPP1Er3pOYhpKCjwAAAAAAAAAAAAAT3rBpvGRkutgBJNwGBLtLSjQL_heqnS42kbnL0Hr8BaXylcKy-AUmiUOskBfvpks_1oQrqD8DRiJr9ZUIAEiAQM34BiS",
    "n_mh": "tOBF_KNaVpFbxj7TWl7PfnsN6W2AIx2kGVG969wbJhs",
    "sid_guard": "9c86c5125097b5051d5123da86567010%7C1757934071%7C5184000%7CFri%2C+14-Nov-2025+11%3A01%3A11+GMT",
    "uid_tt": "8e9c6ece395472698d11ec48e07ba6ed",
    "uid_tt_ss": "8e9c6ece395472698d11ec48e07ba6ed",
    "sid_tt": "9c86c5125097b5051d5123da86567010",
    "sessionid": "9c86c5125097b5051d5123da86567010",
    "sessionid_ss": "9c86c5125097b5051d5123da86567010",
    "is_staff_user": "false",
    "sid_ucp_v1": "1.0.0-KDAyMjQxZDc5NWExNzUxYzBiNDlmZDE0MjJjYzA3NDkyY2U3OGJhN2MKIQiQ94Ci1MyxBhD345_GBhjvMSAMMIaJ0bIGOAdA9AdIBBoCbGYiIDljODZjNTEyNTA5N2I1MDUxZDUxMjNkYTg2NTY3MDEw",
    "ssid_ucp_v1": "1.0.0-KDAyMjQxZDc5NWExNzUxYzBiNDlmZDE0MjJjYzA3NDkyY2U3OGJhN2MKIQiQ94Ci1MyxBhD345_GBhjvMSAMMIaJ0bIGOAdA9AdIBBoCbGYiIDljODZjNTEyNTA5N2I1MDUxZDUxMjNkYTg2NTY3MDEw",
    "login_time": "1757934070021",
    "biz_trace_id": "774282ac",
    "_bd_ticket_crypt_cookie": "baa80d8828ab75b1835c0dec200edbc6",
    "__security_mc_1_s_sdk_sign_data_key_web_protect": "bd5d9526-4db9-bc56",
    "__security_mc_1_s_sdk_cert_key": "87624ec6-40c4-b364",
    "__security_server_data_status": "1",
    "session_tlb_tag": "sttt%7C1%7CnIbFElCXtQUdUSPahlZwEP________-jkHFClPh5-fGqeGoSOJqag5F6losP1KyfHzUZckE6ssk%3D",
    "INVISIBLE_QUERY": "%22enter_from_merge%3Dpage_refresh%22",
    "IsDouyinActive": "false",
    "xg_device_score": "7.991490289911844",
    "live_can_add_dy_2_desktop": "%221%22"
}

params = {
    "device_platform": "webapp",
    "aid": "6383",
    "channel": "channel_pc_web",
    "room_id": "7550169616100199206",
    "author_id": "2707461845550324",
    "offset": "0",
    "limit": "20",
    "pc_client_type": "1",
    "pc_libra_divert": "Windows",
    "update_version_code": "170400",
    "support_h265": "1",
    "support_dash": "0",
    "version_code": "320100",
    "version_name": "32.1.0",
    "cookie_enabled": "true",
    "screen_width": "1920",
    "screen_height": "1080",
    "browser_language": "zh-CN",
    "browser_platform": "Win32",
    "browser_name": "Chrome",
    "browser_version": "142.0.0.0",
    "browser_online": "true",
    "engine_name": "Blink",
    "engine_version": "142.0.0.0",
    "os_name": "Windows",
    "os_version": "10",
    "cpu_core_num": "16",
    "device_memory": "8",
    "platform": "PC",
    "downlink": "10",
    "effective_type": "4g",
    "round_trip_time": "50",
    "webid": "7550268901125637673",
    "msToken": "RVk4zHzk8u6yBkBnVAdxhsWZA9BKejl5SLomVMu4vJxXThofieyhvFz7IpUJjDqUaT2-eJpFB704hGaaU_DFsqKmbeRMb_6i5hthlWkmxqDctr5hakTFfamfVy_1_0seYlPcleC2K7Rf76yE8-M0RE5MGCtIRyT-UmLAWsQdoFii",
    "a_bogus": "mJ0jDw7iYNmnKd/tYOnye1xUXo2/NBSyqaToRCxK9NOYcHUbr8PUEPSOjoLzWDV90bpswqV75nFlbdnczdUs12rkomkfuu4SMz25IysLgqZvP-ig7N8EebGEoiTY0AGYm/Aci/4RIsMF2xQWVq9kApIHK/3NmcEdFr-vVMujY9usUWWjho/Aa-72YhzqSj=="
}
fp = execjs.compile(open("verifyFp.js",'r',encoding="utf-8").read()).call("fp")

params['verifyFp'] = fp
params['fp'] = fp
encode_params_string = urllib.parse.urlencode(params,safe="=")
url = 'https://live.douyin.com/live/promotions/page/?' + encode_params_string
a_bogus = execjs.compile(open("main.js",'r',encoding="utf-8").read()).call("get_abgous",url)
print(a_bogus)
params['a_bogus'] = a_bogus
response = requests.post(url, headers=headers, cookies=cookies, params=params)

print(response.text)
print(response)